/*
 * jxSwing Project (2014)
 * 
 * by Denilson Edinaldo Pinto
 * 
 * LGPL
 * Copyright (C) 2014
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.jxSwing.component.spinner;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author Denilson Edinaldo Pinto
 * @porject jxSwing
 * @package org.jxSwing.component.spinner
 * @date 16/05/2014 - 18:46:08
 */
public final class YearSpinner extends DateSpinner {
	
	private static final long serialVersionUID = 2920332576383516157L;
	
	/**
	 * 
	 */
	public YearSpinner() {
	
		super("yyyy");
		
		setSize(70, 25);
	}
	
	/**
	 * @return Year
	 */
	public final int getYear() {
	
		return getNow().get(Calendar.YEAR);
	}
	
	/**
	 * 
	 */
	public final void setNext() {
	
		setValue(getYear() + 1);
	}
	
	/**
	 * 
	 */
	public final void setNow() {
	
		setValue(new Date());
	}
	
	/**
	 * 
	 */
	public final void setPrevious() {
	
		setValue(getYear() - 1);
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jxSwing.component.spinner.DateSpinner#setValue(java.lang.Object)
	 */
	@Override
	public void setValue(final Object value) {
	
		//
		if(value instanceof Integer) {
			
			try {
				//
				super.setValue(new SimpleDateFormat("yyyy").parse(String.valueOf(value)));
				
			}catch(final ParseException parseException) {
				
				parseException.printStackTrace();
			}
			
		}else {
			
			super.setValue(value);
		}
	}
	
	/**
	 * @param year
	 */
	public final void setYear(final int year) {
	
		setValue(year);
	}
}
